/*
 * Copyright 2010 - Jeremie Brebec
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.jb.ui.user.client;

import org.jb.user.client.LoginPanel;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;

@Singleton
public class LoginPanelImpl implements LoginPanel {

	/*
	 * (non-Javadoc)
	 * @see org.jb.user.client.LoginPanel#failed()
	 */
	@Override
	public void failed() {
		if (dialog != null)
			dialog.failed();
	}

	/*
	 * (non-Javadoc)
	 * @see org.jb.user.client.LoginPanel#hide()
	 */
	@Override
	public void hide() {
		try {
			dialog.hide();
		}
		catch( Exception e ) {
			
		}
		finally {
			dialog = null;
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.jb.user.client.LoginPanel#setListener(org.jb.user.client.LoginPanel.LoginPanelListener)
	 */
	@Override
	public void setListener(LoginPanelListener listener) {
		this.listener = listener;
	}

	/*
	 * (non-Javadoc)
	 * @see org.jb.user.client.LoginPanel#show()
	 */
	@Override
	public void show() {
		if (dialog == null) {
			dialog = loginDialogFactory.get();
			dialog.setListener( listener );
		}
		
		dialog.show();
	}
	
	private LoginPanelListener listener;
	private LoginDialog dialog;
	
	@Inject
	private Provider<LoginDialog> loginDialogFactory;

}
